NestJS redirect URI mismatch 문제 {OAUTH2}

project
false
area
false
resource
true
status
No value
aliases
No value
tags
passport oauth nestjs troubleshooting
description
No value
title
NestJS redirect URI mismatch 문제 {OAUTH2}
created
2023-11-14T21:21:34
updated
2026-07-29T13:03:36

두 가지 엔드포인트가 있다.

sequenceDiagram
    actor User
    participant Client
    participant NestJS
    participant Google

    User ->> Client: Google 계정으로 로그인
    Client ->> NestJS: GET /auth/google

    NestJS -->> Client: Google 로그인 URL로 리다이렉트
redirect_uri 포함 Client ->> Google: GET /o/oauth2/v2/auth
client_id + redirect_uri Google ->> User: Google 로그인 및 동의 요청 User ->> Google: 계정 인증 및 권한 동의 Google -->> Client: redirect_uri로 리다이렉트
Authorization Code 포함 Client ->> NestJS: GET /auth/google/redirect
?code={authorization_code} NestJS ->> Google: Authorization Code로
Access Token 및 Refresh Token 요청 Google -->> NestJS: Access Token
Optional Refresh Token NestJS ->> Google: Access Token으로 사용자 정보 요청 Google -->> NestJS: User data NestJS ->> NestJS: 사용자 DB 조회 및 추가 NestJS -->> Client: Authentication success Client -->> User: 로그인 완료

구현 플로우

TroubleShooting

엔드포인트 정의부 마지막에는 꼭 /를 붙여주세요.

before

@Controller('auth')

after

@Controller('auth/')